package com.tarry.websocket.web;

import com.tarry.websocket.domain.WiselyMessageDto;
import com.tarry.websocket.domain.WiselyResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

@Controller
@Slf4j
public class WsController {

    /**
     *
     * @param wiselyMessageDto
     * @return
     * @throws Exception
     */
    @MessageMapping("/welcome")
    @SendTo("/topic/getResponse")//当服务端有消息时，会像订阅者发送消息
    public WiselyResponseDto say(WiselyMessageDto wiselyMessageDto)throws Exception{
        Thread.sleep(3000);
        log.info("name is " + wiselyMessageDto.getName());
        return new WiselyResponseDto("Welcome,"+wiselyMessageDto.getName()+"!");
    }
}
